package UF_SQLCON;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

public class Example {
    public List<String> order() {
        final List<String> strings = new ArrayList<String>();
        populate(strings, 1, 3, 5, 7, 9);
        populate(strings, 0, 2, 4, 6, 8);
        return strings;
    }

    public void populate(List<String> data, int... keys) {
        try {
            Connection conn = null;
            PreparedStatement ps = conn.prepareStatement("SELECT * FROM Table where key=?");
            try {
                for (int key : keys) {
                    ps.setInt(1, key);
                    final ResultSet resultSet = ps.executeQuery();
                    try {
                        populate(data, resultSet);
                    } finally {
                        resultSet.close();
                    }
                }
            } catch (SQLException e) {
                conn.close();
            }  finally {
                ps.close();
            }
        } catch (SQLException e) {
            // do nothing
        }
    }

    public void populate(List<String> data, ResultSet rs) throws SQLException {
        while (rs.next()) {
            String s = rs.getString(1);
            data.add(s);
        }
    }
}
